Title: x86assembly - class2 - basics - video notes
Tags: ch2

An integer constant, or integer literal, is made up of an optional leading sign, one or more digits, and optional suffix character called a radix indicating the number's base.
[{+ | -}] digits [radix]
Topic: const

A radix may be one of the following.
h
hexadecimal
q | o
octal
d | t
decimal (optional - this is the default)
b | y
binary
r
encoded real
Topic: radix

Q: A decimal [...] contains an optional sign, followed by an integer, a required decimal point, an optional integer expressing a fraction, and an optional exponent.
Syntax: [sign]integer.[integer][exponent]
The exponent portion is expressed as E[{+|-}]integer
e.g:
2.
+3.0
-44.2E+05
26.E5
A: real
Extra: link functional
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=6
Topic: decimal

Q: [...] and [...] constants can be enclosed in single or double quotes. A mix can be used to include quote characters in strings.
E.g. 'Say "Goodnight," Gracie'
A: Character; string
Extra: link functional
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=6
Topic: const

Reserved words cannot be used as identifiers. They have special meaning and can only be used in their correct context.
Reserved words include:
- mnemonics (MOV, ADD, MULL),
- directives, (.data .code PROC)
- type attributes (BYTE, WORD),
- register names (EAX, EH),
- operators (+, MOD, *, /, ()),
- and predefined symbols (@data).
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=2
Topic: identifiers

An identifier is a programmer-chosen name. It may identify a variable, constant, procedure, or code label.
An identifier can contain between 1 and 247 characters and are not case sensitive.
The first letter must be a letter, underscore, @, ?, or $.
Subsequent characters may be digits.
An identifier cannot be the same as a reserved word.
Generally, using @ to begin an identifier is bad practice, because so many predefined symbols use it.
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=2
Topic: names

A directive is a command embedded in the source code that is recognized and acted upon by the assembler. They do not execute at runtime.
Directives can define variables, macros and procedures. They can assign names to memory segments and perform other housekeeping tasks related to the assembler. They are case insensitive .
e.g.: myVar DWORD 26
DWORD is a directive assigning 26 to a 32 bit memory location referenced by myVar.
e.g: mov eax, myVar
MOV is a directive instruction which moves contents of memory location myVar to the 32 bit register EAX
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=2
Topic: commands

Program sections, or segments, identify parts of the program.
The .DATA / .data directive identifies the area of the source code containing variables.
The .CODE / .code directive identifies the area of the source code containing executable instructions.
The .STACK / .stack directive identifies the area of the program holding the runtime stack, setting its size. E.g: .stack 100h
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=3
Topic: src code parts

An instruction is a statement that becomes executable when a program is assembled. They are translated by the assembler into machine language bytes which are loaded and executed by the CPU at runtime.
An instruction contains four basic parts:
1. Label (optional)
2. mnemonic (required)
3. Operand(s) (usually required)
4. Comment (optional)
Extra: Syntax: [label:] mnemonic [operands] [;comment]
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=1

A label is an identifier for instructions and data. A label placed just before an instruction implies the instruction's address. If it's placed before a variable, it implies the variable's address. The assembler assigns a numeric address to each label. Multiple data items can then follow a label, and will be stored in order at that memory location.
A label in the  .code  area of a program, where instructions are located, must end with a colon (:) character.
Code labels are used as targets of jumping and looping instructions.
A code label can share the same line with an instruction, or it can be on a line by itself.
example:
target:
   move ax bx
   ; ...
   jmp target
In this example, the label is target.
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=1
Topic: identifiers

An instruction mnemonic is a short word that identifies an instruction.
mov val1, val2
assign val2 to val1
add val1, val2
add val2 to val1
sub val1, val2
subtract val2 from val1, store in val1
mul val1, val2
multiply val2 by val1, store in val1
jmp off
move instruction pointer to address labeled off
call proclabel
call procedure labeled proclabel
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=2
Topic: instructions

Assembly language instructions can have between zero and three operands.
Each operand can be:
- a register
- a memory operand specified by:
  - the name of a variable
  - register(s) containing the address of a variable
- a constant expression
- an input/output port
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=25
Topic: instructions

Q: There are two ways to do comments. A single-line comment begins with a [...] and all the rest of the characters on the same line are ignored.
Block comments begin with a [...] directive and any user-specified symbol. All subsequent lines are ignored until the same symbol reappears.
1
2
3
4
[...]  !
  line
  line
!
A: semicolon (;); COMMENT; COMMENT
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=2
Topic: documenting

Q: The [...] instruction is short for "No operation". It takes 1 byte of storage and does nothing. It's sometimes used to align code to even-address boundaries or adjust time in a segment of code.
A: NOP
Topic: instructions

The intrinsic data types in x86 assembly are:
BYTE
8 bit unsigned integer
SBYTE
8 bit signed integer
WORD
16 bit unsigned integer
SWORD
16 bit signed integer
DWORD
32 bit unsigned integer
SDWORD
32 bit signed integer
FWORD
48 bit integer
QWORD
64 bit integer
TBYTE
80 bit (10 byte) integer
REAL4
32 bit (4-bye) IEEE short real
REAL8
64 bit (8-byte) IEEE long real
REAL10
80 bit (10-byte) IEEE extended real
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=4
Topic: intrinsic data types

A data definition statement, essentially variable assignment, sets aside storage in memory for a variable, with an optional name.
Syntax: [name] directive initialValue [,initialValue]
Where directive  is an intrinsic data type.
If multiple initial values are provided, the same size memory will be allocated sequentially for each.
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=5
Topic: identifiers

The x86 stores and retrieves data using little endian order, meaning it goes low-to-high.
The least significant byte is stored at the first memory address allocated for data and the most signficant byte is stored at the last memory address allocated for data.
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=8
Topic: addressing

The equal-sign directive associates a symbol name with a 32-bit integer expression.
e.g. COUNT = 500
In this example, COUNT is called a symbolic constant.
When the program is assembled, all occurences of the name are replaced by the expression during the preprocessing step.
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=9
Topic: initialization

Q: The [...] directive works similarly to the = directive, but it can also assign non-integer constants.
e.g. prompt [...] <"press any key",0>
e.g. Pi [...] <3.14>
A: EQU; EQU; EQU
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=10
Topic: assignment

Q: To determine the number of bytes allocated to a storage space, subtract the address after the space from the address begining the space.
The [...] references the starting address of the space while [...] is a reserved word referencing the current location counter.
This must be done immidietely after the memory has been allocated.
E.g.
1
2
list BYTE 10,20,30,40
listSize = ($ - list)
A: identifier; $
Extra: link works
url: https://www.csie.ntu.edu.tw/~cyy/courses/assembly/08fall/lectures/handouts/lec11_x86Asm_4up.pdf#page=10
Topic: addresses